package com.yxkj.syh.app.huarong.activities.user.appointment;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableField;

import com.syh.app.basic.base.BaseResponse;
import com.syh.app.basic.base.view_model.BaseViewModel;
import com.syh.app.basic.utils.Tooast;
import com.syh.app.basic.utils.net.ApiObserver;
import com.trello.rxlifecycle2.android.ActivityEvent;
import com.yxkj.syh.app.huarong.bean.ReturnCar;
import com.yxkj.syh.app.huarong.bean.ReturnCarResponse;
import com.yxkj.syh.app.huarong.data_center.model.ReportModel;

/**
 * 创建者：SYH
 * 时间：2020/6/4 9:26
 * 编辑者：SYH、
 * 标签：
 * 补充说明：
 */
public class AppointmentVM extends BaseViewModel<ActivityEvent> {

    public AppointmentVM(@NonNull Application application) {
        super(application);
    }

    public ObservableField<String> ofFrom = new ObservableField<>();
    public ObservableField<String> ofTo = new ObservableField<>();
    public ObservableField<String> ofAppointmentTime = new ObservableField<>();
    public ObservableField<String> ofCarID = new ObservableField<>();
    public ObservableField<String> ofRemark = new ObservableField<>();

    public void apointmentInfo(long id){
        ReportModel.getReportModel().returnCarInfo(id,mLifecycleProvider.bindToLifecycle(), new ApiObserver<ReturnCarResponse>() {
            @Override
            public void onSuccess(ReturnCarResponse carResponse) {
                ReturnCar returnCar = carResponse.getData();
                ofFrom.set(returnCar.getStartArea());
                ofTo.set(returnCar.getEndArea());
                ofAppointmentTime.set(returnCar.getSubscribeTime());
                ofCarID.set(returnCar.getCarNo());
                ofRemark.set(returnCar.getRemark());

            }

            @Override
            public void onFailed(int code, String msg) {
                Tooast.warning(msg);
            }
        });
    }

    public void unAppointment(long id){
        ReportModel.getReportModel().unappointment(id, mLifecycleProvider.bindToLifecycle(), new ApiObserver<BaseResponse>() {
            @Override
            public void onSuccess(BaseResponse response) {
                Tooast.success(response.getMessage());
                finish();
            }

            @Override
            public void onFailed(int code, String msg) {
                Tooast.warning(msg);
            }
        });
    }

}
